package com.changgou.pay.mq.queue;

/**
 * 必须有队列监听，否则不能创建队列和exchange
 */

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Configuration
public class PayMqConfig {
    //读取配置文件的内容
    @Autowired
    private Environment evn;

    @Bean
    public Queue orderQueue() {
        return new Queue(evn.getProperty("mq.pay.queue.pay"));
    }
    @Bean
    public Exchange orderExchange() {
        return new DirectExchange(evn.getProperty("mq.pay.exchange.pay"), true, false);
    }

    @Bean
    public Binding orderSeckillExchange(Queue orderQueue, Exchange orderExchange) {
        return BindingBuilder.bind(orderQueue).to(orderExchange).with(evn.getProperty("mq.pay.routing.pay")).noargs();
    }

    @Bean
    public Queue ordeSeckillrQueue() {
        return new Queue(evn.getProperty("mq.pay.queue.seckillpay"));
    }

    @Bean
    public Exchange orderSeckillExchange() {
        return new DirectExchange(evn.getProperty("mq.pay.exchange.seckillpay"), true, false);
    }

    @Bean
    public Binding orderSeckillQueueExchange(Queue ordeSeckillrQueue, Exchange orderSeckillExchange) {
        return BindingBuilder.bind(ordeSeckillrQueue).to(orderSeckillExchange).with(evn.getProperty("mq.pay.routing.seckillpay")).noargs();
    }
}
